

/*
clean measures of financial crises
input data downloaded from various sources

output:
- hkm_*.dta: daily/monthly HKM intermediary ratio data
- rr_us_fincrisis.dta: R&R financial crisis indicator for US

*/


********************************************************************************
********************************************************************************
* HKM data

* monthly
import delim ../data/input/He_Kelly_Manela_20221001/He_Kelly_Manela_Factors_monthly_221001.csv, ///
	delim(",") clear
* stata-format date
tostring yyyymm, replace
gen _year = substr( yyyymm, 1, 4)
gen _month = substr( yyyymm, 5, 2)
destring _year _month, replace
gen ym = ym(_year, _month)
drop _year _month
format ym %tm

rename intermediary_capital_ratio icr_level
rename intermediary_capital_risk_factor icr_ar1_shock
order ym icr_level icr_ar1_shock
keep ym icr_level icr_ar1_shock
save ../data/hkm_monthly.dta, replace


* daily
import delim ../data/input/He_Kelly_Manela_20221001/He_Kelly_Manela_Factors_daily_221001.csv, ///
	delim(",") clear
tostring yyyymmdd, replace
gen _year = substr( yyyymmdd, 1, 4)
gen _month = substr( yyyymmdd, 5, 2)
gen _day = substr( yyyymmdd, 7, 2)
destring _year _month _day, replace
gen date = mdy(_month, _day, _year)
drop _year _month _day
format date %td

rename intermediary_capital_ratio icr_level
rename intermediary_capital_risk_factor icr_ar1_shock
order date icr_level icr_ar1_shock
keep date icr_level icr_ar1_shock
save ../data/hkm_daily.dta, replace



********************************************************************************
********************************************************************************
* RR data
* input in misc data directory
use ../data/input/RomerandRomerFinancialCrises/RR_us_fincrisis.dta, clear
drop year halfyear
order yh crisis
rename crisis rr_crisis
* labels
label define rr 0 "No distress" ///
	1 "Credit disruption–minus" ///
	2 "Credit disruption–regular" ///
	3 "Credit disruption–plus" ///
	4 "Minor crisis–minus" ///
	5 "Minor crisis–regular" ///
	6 "Minor crisis–plus" ///
	7 "Moderate crisis–minus" ///
	8 "Moderate crisis–regular" ///
	9 "Moderate crisis–plus" ///
	10 "Major crisis–minus" ///
	11 "Major crisis–regular" ///
	12 "Major crisis–plus" ///
	13 "Extreme crisis–minus" ///
	14 "Extreme crisis–regular" ///
	15 "Extreme crisis–plus"

label values rr_crisis rr
save ../data/rr_us_fincrisis.dta, replace




